<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class S3r_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_anggaran($data){
		$this->db->insert('ANGGARAN',$data);
	}
	
	function get_s3r_grid(){	
		$table_name = "s3r";
		$this->db->select('*');
		$this->db->from($table_name);
		$this->db->join('daerah', 's3r.ID_DAERAH = daerah.ID_DAERAH', 'left');
		$this->db->join('satuan', 's3r.ID_SATUAN = satuan.ID_SATUAN', 'left');
		$this->CI->flexigrid->build_query();
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from($table_name);
		$this->db->join('daerah', 's3r.ID_DAERAH = daerah.ID_DAERAH', 'left');
		$this->db->join('satuan', 's3r.ID_SATUAN = satuan.ID_SATUAN', 'left');
		$this->CI->flexigrid->build_query(FALSE);
		$return['record_count'] = $this->db->count_all_results();
		return $return;
	}
	
	function delete_anggaran($id_anggaran){
		$data = array(
			'STATUS' 			=> 0
		);
		$this->db->where('IDANGGARAN',$id_anggaran);
		$this->db->update('ANGGARAN',$data);
	}
	
	function get_anggaranID($id_anggaran){
		$this->db->select("*");
		$this->db->from('ANGGARAN');
		$this->db->where('IDANGGARAN',$id_anggaran);
		$query = $this->db->get();
		return $query;
	}
	
	function get_anggaran(){
		$this->db->select("*");
		$this->db->from('ANGGARAN');
		$this->db->where("STATUS > 0 ");
		$this->db->order_by('TAHUN');
		$query = $this->db->get();
		return $query;
	}
	
	function update_anggaran($data,$id_anggaran){
		$this->db->where('IDANGGARAN',$id_anggaran);
		$this->db->update('ANGGARAN',$data);
	}
	
}

?>